<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<head>
<%
     String path=request.getContextPath();
     String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>注册</title>
<link rel="stylesheet" href="<%=basePath%>/frame/layui/css/layui.css">
    <link rel="stylesheet" href="<%=basePath%>/frame/static/css/style.css">
    <link rel="icon" href="<%=basePath%>/frame/static/image/code.png">
<link rel="stylesheet" href="<%=basePath%>layui/css/layui.css" media="all"/>
<script src="<%=basePath%>layui/layui.js"></script>
</head>
<body>
<div>
<div class="login-main">
    <header class="layui-elip">注册页</header>
    ${register}
    <form class="layui-form layui-form-pane" action="javascript:" method="post">
        <div class="layui-input-inline">
            <input type="text" name="name" required  lay-verify="required" placeholder="用户名" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="password" name="password" required  lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="text" name="age" required  lay-verify="required" placeholder="年龄" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
           <select name="roleid" lay-verify="">
              <option value="2">用户</option>
              <option value="1" disabled="">管理员</option>
           </select>
        </div>
        <div class="layui-input-block">
              <button class="layui-btn" lay-submit lay-filter="Demo">立即提交</button>
              <button type="reset" class="layui-btn layui-btn-primary">重置</button>
       </div>
        <hr/>
        <p><a href="login.jsp" class="fl">已有账号？立即登录</a><a href="javascript:;" class="fr">忘记密码？</a></p>
    </form>
</div>
<script src="<%=basePath%>/frame/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form','layer'], function(){
        var form= layui.form;
        var $= layui.jquery;
        var layer = layui.layer;
        form.on('submit(Demo)', function(data){
            var d=data.field
            $.ajax({
            	url:'user/register',
            	type:'post',
            	data:d,
            	success:function(data){
            		if(data>0){
            		layer.msg('注册成功,正在前往登陆,请稍后...',{icon:1});
            		setTimeout(function () {
						window.location.href='login.jsp';
                    }, 3000);
            		}else{
            			layer.msg('注册失败,请重填信息！！！',{icon:2});
            			setTimeout(function () {
                            window.location.reload();
                        }, 2000);
            		}
            	}
            	
            })
          });
    });
</script>
</body>
</html>